//
//  StatusRetweetedCell.swift
//  HMWeibo
//
//  Created by wulei on 15/12/13.
//  Copyright © 2015年 wulei. All rights reserved.
//

import UIKit
import SnapKit

class StatusRetweetedCell: StatusCell {
    
    // MARK: - 视图模型
    // 微博视图模型: 如果继承了父类的属性
    // 不需要 override
    // 不需要 super
    // 先执行父类的 didSet 再执行子类的 didSet
   override var ViewModel: HMStatusViewModel? {
        didSet{
            
            
            retweetLabel.text = ViewModel?.retweetedText
            
            // 测试配图高度
            // 如果动态修改约束高度,可能导致行高计算错误
            pictureView.snp_updateConstraints { (make) -> Void in
                
                
                let offset = ViewModel?.thumbnailUrls?.count > 0 ? StatusCellMargin: 0
                make.top.equalTo(retweetLabel.snp_bottom).offset(offset)
        }
    }
}

    // MARK: - 懒加载控件
    // 背景按钮
   private lazy var backButton: UIButton = {
       let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
        
    }()
    
    // 转发标签
   private lazy var retweetLabel: UILabel = {
        let lbl = UILabel(title: "转发微博", fontSize: 14, color: UIColor.darkGrayColor(), screenInset: StatusCellMargin)
        return lbl
    }()
    

}

extension StatusRetweetedCell {
    override func setupUI() {
        super.setupUI()
        
        // 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetLabel, aboveSubview: backButton)
        
        // 添加约束 自动布局
        // 背景按钮
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
            
        }
        
        // 转发标签
        retweetLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
        
        // 配图视图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetLabel.snp_left)
//            make.width.equalTo(300)
//            make.height.equalTo(90)
        }
        

        
    }
}